package com.wenan.ui.controls.listBoxes
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	import mx.collections.ArrayCollection;
	import mx.controls.DataGrid;
	import mx.controls.listClasses.ListBaseContentHolder;
	
	public class DataGridSpecial extends DataGrid
	{
		[Embed('assets/reportItems/dataGridLine.png')]
		private var lineBitMap:Class;
		public function DataGridSpecial()
		{
			super();
		}
		override protected function drawLinesAndColumnBackgrounds():void
		{
			
		}
		override protected function drawRowGraphics(contentHolder:ListBaseContentHolder):void
		{
			
			var curRow:int = 0;
			
			var i:int = 0;
			var actualRow:int = verticalScrollPosition;
			var n:int = contentHolder.listItems.length;
			
			while (curRow < n)
			{
				var bitmap:Bitmap=new lineBitMap();
				contentHolder.addChildAt(bitmap, 0);
				bitmap.y= (contentHolder.rowInfo[curRow].y+contentHolder.rowInfo[curRow].height ) -1;
				curRow++;
				actualRow++;
			}
			
		}
		override public function get selectedItem():Object
		{
			var items:Array = selectedItems;
			if (items && items.length > 0)
			{
				return items[0];
			}
			return null;
		}
		
		override public function set selectedItem(item:Object):void 
		{
			selectedItems = [item];
		}
		
		override public function get selectedItems():Array 
		{
			var coll:Array = new Array();
			var s:ArrayCollection = dataProvider as ArrayCollection;
			for (var i:int=0; i<s.length; i++) {
				if (s[i]["selected"]) {
					coll.push(s[i]);
				}
			}
			return coll;
		}
		
		override public function set selectedItems(items:Array):void 
		{
			var temp:ArrayCollection = this.dataProvider as ArrayCollection;
			if (items.length > 0)
			{
				for each (var obj:Object in items)
				{
					for (var m:int=0; m<temp.length; m++)
					{
						if (obj.name == temp[m].name)
						{
							temp[m]["selected"] = true;
							break;
						}
					}
				}
				this.invalidateList();
			}
		}
		
		public function notSelectAll():void
		{ 
			var s:ArrayCollection = ArrayCollection(this.dataProvider);  
			for(var i:int=0;i<s.length;i++)
			{ 
				if(s[i]["selected"])
				{  
					s[i]["selected"] = false;
				}
			}         
			this.invalidateList();
		}
		
	}
}